package com.lyluly.coursemgmt.servicemodule.iService.serviceImpl;

import com.lyluly.coursemgmt.servicemodule.iDao.TeacherMapper;
import com.lyluly.coursemgmt.servicemodule.iService.ITeacherService;
import com.lyluly.coursemgmt.servicemodule.model.Teacher;
import com.lyluly.coursemgmt.servicemodule.model.TeacherExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TeacherServiceImpl implements ITeacherService {
    @Autowired
    private TeacherMapper teacherMapper;

    public void addTeacher(Teacher teacher) {
        teacher.setCreatetime(new Date());
        teacherMapper.insert(teacher);
    }

    public Teacher findTeacherById(String tId) {
        Teacher teacher = teacherMapper.selectByPrimaryKey(tId);
        return teacher;
    }

    public List<Teacher> findTeacherListByName(String tName) {
        TeacherExample teacherExample = new TeacherExample();
        teacherExample.or().andTNameEqualTo(tName);
        List<Teacher> teacherList = teacherMapper.selectByExample(teacherExample);
        return teacherList;
    }

    public List<Teacher> findTeacherList() {
        List<Teacher> teacherList = teacherMapper.selectByExample(null);
        return teacherList;
    }

    public void modifyTeacher(Teacher teacher) {
        teacherMapper.updateByPrimaryKeySelective(teacher);
    }

    public void removeTeacherById(String tId) {
        teacherMapper.deleteByPrimaryKey(tId);
    }
}
